pro Hyspectra_cal_correct_patch
  COMPILE_OPT IDL2
  ENVI,/RESTORE_BASE_SAVE_FILES
  ENVI_BATCH_INIT
  
  work_dir=dialog_pickfile(title='打开文件夹',/DIRECTORY)
  image_files=file_search(work_dir,'*.bil',count=numfiles)  
  image_dir_Result=DIALOG_PICKFILE(TITLE='请选择结果保存文件夹',/DIRECTORY)
  fn=dialog_pickfile(title='open the data')
  cd,work_dir
  envi_open_file,fn,r_fid=fid
  if (fid eq -1) then begin
    envi_batch_exit
    return
  endif
  envi_file_query,fid,ns=ns,nl=nl,nb=nb,dims=dims
  
  fn_calib=dialog_pickfile(filter='*.txt',title='定标系数文件')
  openr,lun,fn_calib,/get_lun
  data=fltarr(2,256)
  readf,lun,data
  free_lun,lun
  gain=data[0,*]
  bias=data[1,*]
  
  L=fltarr(ns,nl,nb)
  for i=0,nb-1 do begin
    data_band=envi_get_data(fid=fid,dims=dims,pos=i)
    L[*,*,i]=gain[i]*data_band+bias[i]
  endfor
  
  o_fn=dialog_pickfile(title='保存为')
  envi_write_envi_file,L,out_name=o_fn,ns=ns,nl=nl,nb=nb,$
    data_type=4,interleave=interleave,offset=offset,bnames=bnames
  DELVAR, L 
  ENVI_BATCH_EXIT
end